<template>
 
    <view class="qualityDetail">
      <view class="nav" :style="{ background: showBg ? '#333' : '' }">
        <global-nav-bar
          type="black"
          left-icon="back"
          :color="showBg ? '#fff' : '#333'"
          :title="navBarTitle"
          :fixed="false"
          :isLeftBackShow="isLeftBackShow"
          backgroundColor="rgba(0, 0, 0, 0)"
        ></global-nav-bar>
      </view>
      <view>
        <image
          class="bg"
          src="https://592800-erised-fresh.oss-cn-shenzhen.aliyuncs.com/upload/20221012/cdbdb2f4d67c21d9e1e8089234d17085.png"
          mode=""
          v-if="!showBg"
        ></image>
      </view>
      <!-- 头部进度条 -->
      <view class="header">
        <elevtor-card
          :msg="{
            ...elevatorDetail,
            elevatorId: this.elevatorId,
            isFull: this.isFull,
            isHistory: isFromHistory,
          }"
        >
        </elevtor-card>
        <!-- 切换状态 -->
        <view
          @click.prevent="changeState"
          v-if="status == 3"
          class="statusArea"
          :style="{
            color: elevatorDetail.isStop == 1 ? '#0091ff' : '#E02020',
            zIndex: showBg ? 110 : 120,
          }"
          >{{ elevatorDetail.isStop == 1 ? "正常运行" : "停梯" }}
          <image
            v-if="elevatorDetail.isStop == 1"
            class="statusSwich"
            src="@/static/images/blue.png"
            mode=""
          ></image>
          <image
            v-if="elevatorDetail.isStop == 2"
            class="statusSwich"
            src="@/static/images/red.png"
            mode=""
          ></image>
        </view>
      </view>
      <view class="addressBox">
        <view class="addressBox_left">
          <view class="top">
            <view class="name">
              <image src="@/static/images/index/buildIcon.svg" mode=""></image>
              <view >{{
                elevatorDetail.buildingName
              }}</view>
            </view>
          </view>
          <view
            class="buildAddress"
            @click.stop="petName(elevatorDetail)"
            v-if="
              elevatorDetail.relationAlias &&
              elevatorDetail.relationAlias.length
            "
          >
            <view class="buildings"
              >项目别名:{{
                elevatorDetail.relationAlias.map((item) => item.alias).join(",")
              }}</view
            >
            <view>
              <uni-icons
                :type="popupShow ? 'arrowup' : 'arrowdown'"
                size="14"
                color="#999;"
              ></uni-icons>
            </view>
          </view>
          <view class="buildAddress" @click.stop="toProjectDetail">{{
            elevatorDetail.buildingAddress
          }}</view>
        </view>
        <view class="addressBox_right">
          <view class="gpsAndCall">
            <view
              class="gpsAndCall_item"
              @click.stop="handleCall(0)"
              v-if="
                elevatorDetail.estateUserList &&
                elevatorDetail.estateUserList.length
              "
            >
              <image src="@/static/images/phone3.png" mode=""></image>
              <view>物业</view>
            </view>
            <view class="gpsAndCall_item guide" @click.stop="handleGuide">
              <image src="@/static/images/locations.png" mode=""></image>
              <view>导航</view>
            </view>
            <view
              class="line"
              v-if="
                elevatorDetail.estateUserList &&
                elevatorDetail.estateUserList.length
              "
            ></view>
          </view>
        </view>
      </view>
      <view class="content_box" :style="{ zIndex: showBg ? '10' : '11' }">
        <view class="progressBar">
          <view class="progressBar_content">
            <view class="progressBar_item">
              <!-- <view class="finishDateContent" v-if="status == 3">
                <view class="label">预计维修结束时间</view>
                <view class="timeArea" @click="showChooseDate">
                  <text>{{ `${dateArr[0]}年` }}</text>
                  <text style="color: #0091ff">
                    {{ `${dateArr[1]}月${dateArr[2]}日` }}
                    <text v-if="todayStr">{{ `(${todayStr})` }}</text>
                    {{ `${dateArr[3]}:${dateArr[4]}` }}
                  </text>
  
                  <image src="@/static/images/edit2.png" mode="" />
                </view>
              </view> -->
              <stautsStep
                :actIndex="[-1, 0, 1, 2, -1, -1, -1][status - 1]"
                :list="options"
                :log="logs"
              >
              </stautsStep>
            </view>
            <view class="userListBox" @click="goTaskSetpPage">
              <user-list lable="执行人员" :list="planDetail.users"></user-list>
            </view>
          </view>
        </view>
        <view class="content_item">
          <view class="title">任务信息</view>
          <view class="falutItem">
            <view class="label">工单类型:</view>
            <view class="tag">{{
              [
                "保养质检",
                "重复故障质检",
                "维保移交质检",
                "安装移交质检",
                "常规质检",
                "维修质检",
              ][workOrderDetail.checkType - 1] || "质量检查"
            }}</view>
          </view>
          <view class="des">
            <view class="label">任务描述:</view>
            <text>{{ workOrderDetail.planDesc || "" }}</text>
          </view>
          <view class="info-item">
            <view
              class="info-item-label"
              v-if="
                workOrderDetail.extWordUrl && workOrderDetail.extWordUrl.length
              "
              >附件:
            </view>
            <view class="info-item-word">
              <view
                class="fileName"
                v-for="(item, index) in workOrderDetail.extWordUrl"
                :key="index"
                @click="handledownload(item)"
              >
                {{ item.name }}
              </view>
            </view>
          </view>
          <view class="imgs">
            <image
              v-for="(it, idx) in workOrderDetail.otherUrl"
              :key="idx"
              @click="preViewFile(workOrderDetail.otherUrl, idx)"
              :src="
                it.key == 'image'
                  ? it.value
                  : it.img || '/static/images/video.png'
              "
              :lazy-load="true"
              mode="aspectFill"
            ></image>
          </view>
          <!-- <view
            class="faultImg"
            v-if="
              workOrderDetail.faultMessageVO &&
              workOrderDetail.faultMessageVO.mfImgUrl &&
              workOrderDetail.faultMessageVO.mfImgUrl.length
            "
          >
            <image-drag-sort
              :disabled="true"
              :list="workOrderDetail.faultMessageVO.mfImgUrl"
            ></image-drag-sort>
          </view> -->
        </view>
        <!-- 最近一次维修保养 -->
        <view
          class="content_item"
          v-if="isFromHistory != 2 && workOrderDetail.lastPlan"
        >
          <last-record
            :msg="{ ...workOrderDetail.lastPlan, ...elevatorDetail }"
          ></last-record>
        </view>
      
        <pass-record
          :status="status"
          :planId="planId"
          :isPlanStatus="isPlanStatus"
          :checkStatus="checkStatus"
          :detail-id="detailId"
          @changePass="changePassResult"
          @updatePassMsg="updatePassMsg"
          v-if="status == 3 || status == 4"
        ></pass-record>
        <view
          class="content_item problemBox"
          v-if="status > 2 && checkStatus > 0"
        >
          <view class="title">问题记录</view>
          <view
            class="emptyBox"
            v-if="
              userSignCount != 0 &&
              status == 3 &&
              maintainMalfunctionHistories.length == 0
            "
          >
            <view
              :class="[
                'empty',
                'flex',
                emptyRecord && maintainMalfunctionHistories.length == 0
                  ? 'errorEmpty'
                  : '',
              ]"
              @click="addRecord"
            >
              <uni-icons color="#999" size="60" type="plusempty" />
              添加问题记录
            </view>
          </view>
          <!-- 问题点记录 -->
          <view
            v-if="maintainMalfunctionHistories.length && elevatorDetail.id"
            class="quality-record"
          >
            <quality-record
              ref="quality-record"
              v-for="(item, index) in maintainMalfunctionHistories"
              :key="item.id"
              :isPlanStatus="isPlanStatus"
              :msg="item"
              :isLast="
                index === maintainMalfunctionHistories.length - 1 ? true : false
              "
              :index="index"
              :order-status="status"
              :planId="planId"
              :elevatorMsg="{
                elevatorId: elevatorDetail.id,
                elevatorName: elevatorDetail.buildingName,
                elevatorAddress: elevatorDetail.elevatorAddress,
              }"
              @editRecord="handleEditRecord"
              @update="updateRecord"
            ></quality-record>
          </view>
        </view>
      </view>
      <!-- 底部部分 -->
      <!-- 开始维修按钮放开 -->
      <view
        class="bottom"
        v-if="
          isFromHistory == 1 &&
          (status == 2 || (status !== 4 && userSignCount == 0))
        "
      >
        <view class="right flex">
          <view class="start flex" @click="handleStart">开始 </view>
        </view>
      </view>
      <!-- 状态是维修中且签到过展示以下按钮 -->
      <view
        class="bottom"
        v-if="
          isFromHistory == 1 &&
          showBtns &&
          status >= 3 &&
          userSignCount > 0 &&
          checkStatus > 0
        "
      >
        <view class="right flex">
          <view class="repariing flex" v-if="status == 3 && userSignCount > 0">
            <view class="blue" v-if="userSignCount != 0" @click="addRecord"
              >添加记录</view
            >
            <view @click="handleFinsh(true)" v-if="userSignCount != 0">
              <view class="add"> 完成任务 </view>
            </view>
          </view>
          <!-- 添加维修记录 -->
          <view
            class="repariing flex"
            v-if="status == 4 && workOrderDetail.updateStatus"
          >
            <view
              class="add"
              v-if="
                userSignCount != 0 ||
                (status == 4 && workOrderDetail.updateStatus)
              "
              @click="addRecord"
              >添加维修记录</view
            >
          </view>
          <view class="start flex" v-if="status === 4">
            <view class="editApplyBtn" @click="toReformList"
              >整改任务申请记录
              <view class="size" v-if="workOrderDetail.childPlanSize > 0">{{
                workOrderDetail.childPlanSize
              }}</view>
            </view>
            <view class="finBtn">已完成</view>
          </view>
        </view>
      </view>

      <!-- 电梯状态弹窗 -->
      <model
        title="请选择电梯状态"
        :maskClick="false"
        @cancle="cancleChange"
        @comfire="comfireChange"
        :visible="visibleEleStatus"
      >
        <view class="change_elevator">
          <view
            @click="changeElevator(1)"
            :class="elevatorStatus === 1 ? 'actElevator' : ''"
            >正常运行</view
          >
          <view
            @click="changeElevator(2)"
            :class="elevatorStatus === 2 ? 'actElevator' : ''"
            >停梯</view
          >
        </view>
      </model>
    
      <record-popup
        :showAlias="recordPopupShow"
        @closedMask="
          () => {
            (recordPopupShow = false), (overflowShow = false);
          }
        "
        aliasType="edit"
      >
        <template slot="customer">
          <add-nopass-record
            ref="add-nopass-record"
            v-if="recordPopupShow"
            @addRecord="handleSubmit"
			:elevatorId="elevatorId"
            :plan-id="planId"
            :checkStatus="checkStatus"
            :detail-id="detailId"
            :list="maintainMalfunctionHistories"
            @update="handleSubmit"
            @hadDone="handleDone"
          ></add-nopass-record>
        </template>
      </record-popup>
      <!-- 弹窗提示 -->
      <model
        title="完成提示"
        comfireTxt="确定"
        :maskClick="false"
        @cancle="visibleShow = false"
        @comfire="finishComfire"
        :visible="visibleShow"
      >
        <view class="completeBox">
          <view>是否完成任务</view>
          <view 
            >注:提交任务后任务记录不可修改</view
          >
        </view>
      </model>
      <!-- 提示上次签到弹框 -->
      <model
        :title="signType == 'in' ? '签到拍照提示' : '签退拍照提示'"
        :maskClick="false"
        @cancle="comfireUseLastImg(false)"
        @comfire="comfireUseLastImg(true)"
        :visible="visibleShowTwo"
      >
        <view class="lastImg" v-if="workOrderDetail.lastSignImg">
          {{
            `是否使用上次${
              signType == "in"
                ? workOrderDetail.lastSignImg.signTime
                : workOrderDetail.lastSignImg.signOutTime
            }【${
              signType == "in"
                ? workOrderDetail.lastSignImg.signTypeStatusDesc
                : workOrderDetail.lastSignImg.signOutTypeStatusDesc
            }工单】的${signType == "in" ? "签到" : "签退"}拍照?`
          }}
        </view>
      </model>
      <!-- 物业电话 -->
      <property-phone
        ref="property"
        @bindClose="closePhone"
        :list="elevatorDetail.estateUserList"
      ></property-phone>
      <aliasPopup
        :showAlias="popupShow"
        :aliasArr="aliasArr"
        @closedMask="closedMask"
      ></aliasPopup>
      <view
        class="signCircle"
        v-if="status == 3 && userSignCount != 0"
        :style="{ left: movable.x + 'px', top: movable.y + 'px' }"
        @touchmove.stop="movableChange"
        @touchend="touchend"
      >
        <view
          class="add"
          @click.stop="showStatusChangeBeforeLeave('')"
          v-if="isPlanStatus"
          >签退</view
        >
        <view class="add" v-if="!isPlanStatus" @click="handleStart"
          >{{ "继续" }}
        </view>
      </view>
 
      <!-- 有未签退的工单 -->
      <model
        title="有未签退的质量工单"
        :maskClick="false"
        comfireTxt="去签退"
        width="500rpx"
        :showCloseIcon="false"
        @cancle="signOutModelVisible = false"
        @comfire="toNotSignOutOrder"
        :visible="signOutModelVisible"
      >
        <not-sign-out-model :msg="checkCanSignOutMsg"></not-sign-out-model>
      </model>
	<previewMedia ref="previewMedia"></previewMedia>
    </view>
  
</template>

<script>

import stautsStep from '@/components/status-special/status-special.vue';
import ElevtorCard from '../components/elevtor-card/elevtor-card.vue';
import LastRecord from '@/components/last-record/last-record.vue';
import AddNopassRecord from './components/add-nopass-record.vue';
import UserList from '@/components/user-list/user-list.vue';
import model from '@/components/model/index.vue';
import GlobalNavBar from '@/components/uni-nav-bar/global-nav-bar';
import PropertyPhone from '@/components/propertyPhone/index.vue'; 
// 记录历史
import QualityRecord from './components/quality-record.vue'; 
import PassRecord from './components/passRceord.vue';
import { getPlanDetail, signIn, signOut } from '@/apis/workOrder.js';
import {
	getZjDetail,
	
	checkFinish,

} from '@/apis/affair.js';
import { getSelectWorkTracks } from '@/apis/taskStepPage.js';

import { mapState, mapActions } from 'vuex';
import {
	elevtorDetail,
	changeElevatorState,
	changeElevatorStoplog,
} from '@/apis/elevator.js';
// 经纬度距离计算
import { getDistance } from '@/utils/tools.js'; 
import { getlocalinfo } from '@/utils/utils.js';
import { getConfig, checkCanSignOut } from '@/apis/sign.js';
import aliasPopup from '@/components/card-dial/aliasPopup.vue';
import NotSignOutModel from '../components/notSignOutModel/index.vue';
// 问题记录弹出框
import recordPopup from './components/pop-up.vue';
// 获取问题接口
export default {
	components: {
		GlobalNavBar,
		
		model,
		stautsStep,
		ElevtorCard,
		LastRecord,
		AddNopassRecord,
		
		UserList,
		PropertyPhone, 
		QualityRecord,
		aliasPopup,
		NotSignOutModel,
		PassRecord,
		recordPopup,
	},
	data() {
		return {
			// 自定义弹出框的值
			overflowShow: false, 
			showchangeTips: false,
			// 顶部导航栏title
			navBarTitle: '', 
			// 完成弹框
			visibleShow: false, 
			workOrderDetail: {
				// 故障信息
				faultMessageVO: {}, 
				// 报障信息
				faultReportVO: {},
				// 故障原因 
				faultReasonVO: {},
				// 维修详情最后一次任务
				lastPlan: {}, 
				maintainmaintainMalfunctionHistories: [],
				planContentUsers: [],
				// 未完成的配件更换数量
				partsCount: 0,
				checkStatus: '',
			},
			signType: 'in',
			elevatorId: '',
			// 任务状态详情
			planDetail: {}, 
			// 我自己是否还未签退
			isPlanStatus: false, 
			userSignCount: 0,
			showPoupup: false,
			options: [
				{
					status: 2,
					name: '待开始',
					icon: '/static/images/step1.png',
					createTime: '',
				},
				{
					status: 3,
					name: '进行中',
					icon: '/static/images/step2.png',
					createTime: '',
				},
				{
					status: 4,
					name: '已完成',
					icon: '/static/images/step3.png',
					createTime: '',
				},
			],
			signinData: {},
			status: '',
			elevatorDetail: {},
			elevatorStop: '',
			imgUrl: [],

			maintainMalfunctionHistories: [],
			planId: '',
			lastPlan: {},
			isEditFlag: false,
			showBg: false,
			imgaddress: '',
			stepList: [],
			isFull: false,
			logs: [],
			// reasonList: [],
			// faultReasonVO: {},
			// 是否在历史详情页面跳转过来,否type=1 是type=2
			isFromHistory: '1',
			otherId: '',
			visibleShowTwo: false,
			// 改变电梯状态
			visibleEleStatus: false, 
			elevatorStatus: 1,
			// isOUtInState: false, //维修完成提示故障原因状态弹窗
			// 有同伴任务数据
			cantUsersArr: [],
			// 确定电梯状态后是否走签退逻辑
			showLeave: false, 
			// 签退后是否走维修完成逻辑(新)
			handFinish: false, 
			dateArr: [],
			// 预计完成时间
			finishDate: '', 
			// showState: false,
			// 是否填充照片
			useLastImg: false,
			config: {},
			// 24小时内是否可以编辑
			updateStatus: false, 
			movable: {
				x: 320,
				y: 0,
				height: 0,
				width: 0,
			},
			emptyRecord: false,
			isLeftBackShow: true,
			// 区分按钮类型发送群消息
			buttonType: null,
			popupShow: false,
			aliasArr: [],
			signOutModelVisible: false,
			checkCanSignOutMsg: {},
			checkStatus: '',
			detailId: '',
			passObj: {
				passDesc: '',
				passUrl: [],
			},
			// 问题记录弹出框
			recordPopupShow: false, 
		};
	},

	async onLoad(e) {
		console.log('质检任务', e);
		this.navBarTitle = this.isFromHistory === '1' ? '质检工单' : '质检工单';
		this.planId = e.planId;
		this.elevatorId = e.elevatorId;

		await this.handleRreshToken();
		uni.$on('isFinsh', async (res) => {
			console.log(res, 'isFinsh');
			if (res === true) {
				// 完成
				this.finishComfire();
				// await this.initData();
			}
		});
	},
	onUnload() {
		uni.$off('isFinsh');
	},
	async onShow() {
		// console.log("onShow");
		uni.showLoading({
			title: '加载中',
			mask: true,
		});
		await this.handleRreshToken();
		uni.hideLoading();
		if (!this.userinfo.user_id) {
			uni.showModal({
				title: '提示',
				content: '检测到您未登录或登录已失效，请前往登录后在操作',
				showCancel: false,
				success: () => {
					uni.navigateTo({
						url: '../login/index',
					});
				},
			});
			return;
		}
		await this.initData();
		// 判断是否已关闭和不是执行人
		// 判断工单是否是执行人
		// console.log(this.status, "status的值");
		let user = this.workOrderDetail.planContentUsers || [];
		let isIncludes = user.findIndex(
			(item) => item.userId == this.userinfo.user_id
		);
		// console.log(user, "user得知", isIncludes);
		let type = 1;
		if (this.status == 7 || isIncludes == -1) {
			console.log('看看这里');
			if (isIncludes == -1) {
				type = 2;
			}
			if (this.status == 7 && isIncludes == -1) {
				type = 1;
			}
		}
	},
	mounted() {
		wx.getSystemInfo({
			success: (res) => {
				console.log('system', res);
				this.movable.height = res.windowHeight - 100;
				this.movable.y = res.windowHeight - 240;
				this.movable.width = res.windowWidth;
				this.movable.x = this.movable.width - 55;
			},
		});
	},
	watch: {
		maintainMalfunctionHistories(val) {
			if (val.length) {
				this.emptyRecord = false;
			}
		},
	},
	computed: {
		...mapState('user', ['userinfo']),
		showBtns() {
			let next = false;
			if (!this.planDetail.users) {
				return next;
			}
			for (let i = 0; i < this.planDetail.users.length; i++) {
				if (this.planDetail.users[i].userId == this.userinfo.user_id) {
					next = true;
					break;
				}
			}
			// console.log(next, "next的值");
			return next;
		},
		finishBtn() {
			return this.maintainMalfunctionHistories.length ? false : true;
		},
	},
	onPageScroll(e) {
		// console.log(e.scrollTop, '滚动')
		if (e.scrollTop > 20) {
			this.navBarTitle = this.elevatorDetail.elevatorAddress;
			this.scrollTop = e.scrollTop;
			this.showBg = true;
		} else {
			this.navBarTitle = '质检工单';
			this.showBg = false;
		}
	},
	methods: {
		...mapActions('user', ['handleRreshToken']),
		// 去整改列表记录
		toReformList() {
			uni.navigateTo({
				url: `/subpages/quality/reformList?planId=${this.planId}`,
			});
		},
		changePassResult(res, list) {
			if (res == 1) {
				this.emptyRecord = false;
			}
			this.checkStatus = res;
			this.maintainMalfunctionHistories = list;
		},
		updatePassMsg(obj) {
			console.log(obj, '获取数据');
			this.getDetail();
			// this.checkStatus = obj.checkStatus;
			// this.passObj.passDesc = obj.passDesc;
			// this.passObj.passUrl = obj.passUrl;
			// console.log(this.checkStatus);
		},
		// async changeCheckStatus(res) {
		//   if (!this.isPlanStatus) {
		//     uni.showToast({
		//       title: "请先签到开始,再进行操作",
		//       icon: "none",
		//       mask: true,
		//     });
		//     return;
		//   }
		//   this.checkStatus = res;

		//   if (this.checkStatus == 1) {
		//     await this.getCheckPassFun();
		//   } else {
		//     // 先获取内容
		//     await this.getCheckNoPassFun();
		//     // 再提交质检通过的内容
		//     checkFinish({
		//       status: 0,
		//       checkStatus: 1,
		//       id: this.workOrderDetail.id,
		//       ...this.passObj,
		//     }).then((res) => {
		//       console.log(res, "提交通过");
		//     });
		//   }
		// },
		// 获取通过内容
		// getCheckPassFun() {
		//   return new Promise((resolve) => {
		//     getCheckPass({ planId: this.planId }).then((res) => {
		//       resolve(res.data);
		//       this.passObj.passUrl = res.data.passUrl || [];
		//       this.passObj.passDesc = res.data.passDesc || "";
		//     });
		//   });
		// },
		// descConfirm(e) {
		//   if (e.detail.value.length >= 300) {
		//     this.passObj.passDesc = e.detail.value.substring(0, 300);
		//   } else {
		//     this.passObj.passDesc = e.detail.value;
		//   }
		// },
		// changeNoticImg(val) {
		//   this.passObj.passUrl = val;
		// },

		// 去为签退工单
		toNotSignOutOrder() {
			uni.navigateTo({
				url: `/subpages/quality/qualityDetail?planId=${this.checkCanSignOutMsg.planId}&elevatorId=${this.checkCanSignOutMsg.elevatorId}`,
			});
			this.signOutModelVisible = false;
		},
		// 项目别名弹窗
		petName(obj) {
			this.popupShow = true;

			this.aliasArr = (obj.relationAlias || []).map((item) => item.alias);
		},
		closedMask() {
			this.popupShow = false;
		},
		// 编辑工作记录
		handleEditRecord(res) {
			// this.$refs.popup.open();
			this.recordPopupShow = true;
			this.overflowShow = true;
			this.$nextTick(() => {
				this.$refs['add-nopass-record'].initRecord({
					...res.msg,
					isEdit: true,
				});
			});
		},
		getValue(url) {
			// 获取最后一个/的位置
			var site = url.lastIndexOf('.');
			// 截取最后一个/后的值
			return url.substring(site + 1, url.length);
		},
		handledownload(plan) {
			uni.showLoading({
				title: '下载中',
				icon: 'none',
			});
			// let str = plan.url.substring(plan.url.indexOf("/") + 44);
			console.log(this.getValue(plan.url), '看看类型');
			wx.downloadFile({
				url: plan.url,
				success: (res) => {
					// console.log(res, "下载的文件");
					if (res.statusCode === 200) {
						this.tempFilePath = res.tempFilePath;
						console.log(this.tempFilePath, 'this.tempFilePath ');
						this.openFile('.' + this.getValue(plan.url));
						uni.hideLoading();
					}
				},
				fail: (err) => {
					console.log(err, '错误');
					uni.hideLoading();
				},
			});
		},
		openFile(type) {
			console.log(this.tempFilePath, 'this.tempFilePath', '打开文件'); 
			// #ifdef H5
			// eslint-disable-next-line no-undef
			sida.openUrl({ url: this.downloadFileUrl });        
			uni.hideLoading();
			// #endif

			// #ifndef h5
			uni.openDocument({
				filePath: this.tempFilePath,
				showMenu: true,
				fileType: type.substring(1), 
				fail: (err) => {
					console.log(err);
				},
			});
			// #endif
		},
		movableChange(e) {
			// console.log('movableChange', e)
			let x = e.touches[0].pageX - 56 / 2;
			let y = e.touches[0].clientY - 56 / 2;
			if (x < 8) {
				x = 8;
			}
			if (x > 330) {
				x = 330;
			}
			if (y < 70) {
				y = 70;
			}
			if (y > this.movable.height + 5) {
				y = this.movable.height + 5;
			}
			this.movable.x = x;
			this.movable.y = y;
		},
		touchend() {
			if (this.movable.x < 156) {
				this.movable.x = 8;
			} else {
				this.movable.x = this.movable.width - 55;
			}
		},
		// 预计完成时间弹框
		// showChooseDate() {
		//   if (!this.isPlanStatus) {
		//     uni.showToast({
		//       title: "请先签到,再进行操作",
		//       icon: "none",
		//       mask: true,
		//     });
		//     return;
		//   }
		//   this.showState = true;
		//   this.$nextTick(() => {
		//     this.$refs.weekYear.$refs.chooseDate.open();
		//   });
		// },
		// bindClose() {
		//   this.showState = false;
		//   this.$refs.weekYear.$refs.chooseDate.close();
		// },
		// selectChange(res) {
		//   this.finishDate = res.date;
		//   let timeArr = res.date.replace(" ", ":").replace(/\:/g, "-").split("-");
		//   this.dateArr = timeArr;
		//   //这里需要请求数据
		//   this.handleTimeUpdate();
		// },
		// 修改预计时间请求数据
		// handleTimeUpdate() {
		//   uni.showLoading({
		//     title: "请求中",
		//     icon: "none",
		//   });
		//   timeUpdate({
		//     id: this.planId,
		//     finishDate: this.finishDate + ":00",
		//   }).then((res) => {
		//     if (res) {
		//       uni.hideLoading();
		//       this.getDetail();
		//     }
		//   });
		// },
		// 预览
		preViewFile(list, index) {
			console.log('预览照片', list, index);
			let url = list.map((item) => {
				return { type: item.key, url: item.value };
			});
			wx.previewMedia({
				sources: url,
				current: index,
			});
		},
		// 配件更换
		// toAddPart() {
		//   let obj = {
		//     planId: this.planId,
		//     elevatorId: this.elevatorId,
		//     buildingName: this.elevatorDetail.buildingName,
		//     elevatorAddress: this.elevatorDetail.elevatorAddress,
		//   };
		//   uni.navigateTo({
		//     url: "/pageModules/parts/partsRecord?obj=" + JSON.stringify(obj),
		//   });
		// },
		// 跳转项目详情
		toProjectDetail() {
			uni.navigateTo({
				url:
          '/pageModules/projectInfo/detail?id=' +
          this.elevatorDetail.buildingId,
			});
		},
		// 修改电梯状态弹窗提示
		changeState() {
			if (this.status === 4) {
				uni.showToast({
					title: '任务已完成',
					icon: 'none',
				});
				return;
			}
			if (!this.isPlanStatus) {
				uni.showToast({
					title: '请先签到开始,再进行操作',
					icon: 'none',
					mask: true,
				});
				return;
			}
			this.visibleEleStatus = true;
			// this.comfireChange();
		},
		cancleChange() {
			this.visibleEleStatus = false;
			this.elevatorStatus = this.elevatorDetail.isStop;
		},

		// 是否使用上次签到签退照片
		comfireUseLastImg(res) {
			console.log(this.handFinish, 8888);
			this.visibleShowTwo = false;
			this.useLastImg = res;
			let data = {
				signType: this.signType == 'in' ? 1 : 2,
				useLastImg: this.useLastImg,
				orderType: 6,
			};
			if (this.buttonType === 1) {
				data.buttonType = 1;
			}
			uni.setStorage({
				key: 'signObj',
				data,
			});

			uni.navigateTo({
				url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}&isFinsh=${this.handFinish}`,
			});
		},
		// 更改电梯状态
		changeElevator(nums) {
			this.elevatorStatus = nums;
		},
		// 电梯状态更改确定
		comfireChange() {
			uni.showLoading({
				title: '加载中',
				icon: 'none',
			});
			// if (this.isOUtInState) {
			//   this.isOUtInState = false;
			//   if (this.cantUsersArr.length > 0) {
			//     this.handleFinsh(false);
			//   } else {
			//     this.$refs.finish.open();
			//     this.handleFinsh(false);
			//   }
			// }
			if (this.elevatorDetail.isStop === this.elevatorStatus) {
				// 选择同状态不请求
				uni.hideLoading();
				this.visibleEleStatus = false;
				if (this.showLeave) {
					this.finishOut('');
				}
				return;
			}
			changeElevatorState({
				id: this.elevatorId,
				isStop: this.elevatorStatus,
			}).then(() => {
				this.visibleEleStatus = false;
				changeElevatorStoplog({
					elevatorId: this.elevatorId,
					initStatus: this.elevatorDetail.isStop,
					setStatus: this.elevatorStatus,
					module: `${this.planId}`,
					position:6
				}).then(() => {
					elevtorDetail({ elevatorId: this.elevatorId }).then((res) => {
						if (res) {
							uni.hideLoading();
							uni.showToast({
								title: '电梯状态切换成功',
								icon: 'none',
							});
							this.elevatorDetail = res.data;
							this.isFull = res.data.isFull;

							if (this.showLeave) {
								this.finishOut('');
							}

							// this.sendStopMsg();
						}
					});
				});
			});
		},

		// 获取任务跟踪进度条
		getSelectWorkTracks() {
			return new Promise((resolve) => {
				getSelectWorkTracks({ planId: this.planId }).then((res) => {
					let workLogs = res.data.workLogs;
					let logs = [];
					for (let i = 0; i < this.options.length; i++) {
						let createTime = '';
						for (let j = 0; j < workLogs.length; j++) {
							if (workLogs[j].planStatus == this.options[i].status) {
								createTime = workLogs[j].createTime;
								break;
							}
						}
						logs.push({ createTime });
					}
					this.logs = logs;
					// this.$forceUpdate();
					resolve();
				});
			});
		},
		// 维保事务任务状态详情是否可以签到，维保员列表等信息
		getPlanDetail() {
			return new Promise((resolve) => {
				getPlanDetail({ planId: this.planId }).then((res) => {
					console.log(res.data, '维保员列表');
					this.planDetail = res.data;
					this.isPlanStatus = this.setIsPlanStatus();
					this.status = res.data.status;
					this.getSelectWorkTracks();
					// console.log(this.isPlanStatus, "this.isPlanStatus的值");
					resolve();
				});
			});
		},
		// 我自己是否还未签退
		setIsPlanStatus() {
			if (!this.planDetail.users) {
				return false;
			}
			for (let i = 0; i < this.planDetail.users.length; i++) {
				if (
					this.planDetail.users[i].userId == this.userinfo.user_id &&
          this.planDetail.users[i].signUser
				) {
					this.userSignCount = this.planDetail.users[i].userSignCount;
					return this.planDetail.users[i].signUser.isPlanStatus;
				}
			}
			this.userSignCount = 0;
			return false;
		},
		// 任务追踪页面
		goTaskSetpPage() {
			console.log('任务跟踪');
			uni.navigateTo({
				url: `/pageModules/taskStepPage/taskStepPage?planId=${this.planId}&elevatorId=${this.elevatorId}&state=4`,
				fail: (err) => {
					console.log(err);
				},
			});
		},
		updataShowFuc(val) {
			this.showPoupup = val;
		},
		handleBack() {
			// console.log(11)
			uni.navigateBack({});
		},
		async initData() {
			uni.showLoading({
				title: '加载中',
				icon: 'none',
			});
			// 获取创建工单记录等记录
			await this.getDetail();
			// 获取任务content详情
			await this.getPlanDetail();
			console.log('222222222222', this.status, this.userSignCount);
			// 获取配置
			await this.getConfig();
			elevtorDetail({ elevatorId: this.elevatorId }).then((res) => {
				if (res) {
					console.log(res);
					this.elevatorDetail = res.data;
					this.elevatorStatus = res.data.isStop;
					this.isFull = res.data.isFull;
					uni.hideLoading();
				}
			});
			// 获取配件
			// getPartListCounts({ planId: this.planId }).then((res) => {
			//   if (res.code === 200) {
			//     this.partsCounts = res.data.disFinishCounts || 0;
			//     this.finishCounts = res.data.finishCounts || 0;
			//   }
			// });

			return;
		},
		// 获取事务工单的创建详情
		getDetail() {
			uni.showLoading({
				title: '加载中',
				icon: 'none',
			});
			return new Promise((resolve) => {
				getZjDetail({ planId: this.planId }).then((res) => {
					if (res) {
						// console.log(res.data, "工单详情");
						this.workOrderDetail = res.data;
						this.checkStatus = res.data.checkStatus;
						this.detailId = res.data.id;
						this.maintainMalfunctionHistories =
              res.data.maintainMalfunctionHistories || res.data.malFunctionHistories || [];
						uni.hideLoading();
						// this.finishDate = res.data.finishDate;
						// if (res.data.finishDate != null) {
						//   let timeArr = res.data.finishDate
						//     .replace(" ", ":")
						//     .replace(/\:/g, "-")
						//     .split("-");
						//   this.dateArr = timeArr;
						// } else {
						//   let date = dayjs().format("YYYY-MM-DD");
						//   let hour = Number(dayjs().format("HH")) + 2;
						//   let min = dayjs().format("mm");
						//   let arr = [...date.split("-"), hour, min];
						//   this.dateArr = arr;
						//   this.finishDate = `${date} ${hour}:${min}`;
						// }
					}
					resolve(res.data.elevatorDetail);
				});
			});
		},
		// 获取经纬度信息
		getLocalInfo() {
			return new Promise((resolve) => {
				if (getApp().globalData.localinfo.latitude) {
					if (
						new Date().getTime() - getApp().globalData.localinfo.time <=
            1000 * 60 * 2
					) {
						resolve(getApp().globalData.localinfo);
						return;
					}
				}

				uni.getLocation({
					type: 'gcj02',
					success(res) {
						console.log('位置信息获取成功', res);
						getApp().globalData.localinfo = {
							...res,
							time: new Date().getTime(),
						};
						resolve(res);
					},
					fail(err) {
						console.log('位置信息获取失败', err);
						resolve({});
					},
				});
			});
		},
		// 签到确认
		// confirmSignIn(distance, res, address) {
		// 	if (this.imgaddress === '') {
		// 		uni.showToast({
		// 			title: '请先上传图片',
		// 			icon: 'none',
		// 		});
		// 		return;
		// 	} else {
		// 		signinPage({
		// 			userId: this.userinfo.user_id,
		// 			planId: this.planId,
		// 			signImage: this.signImg.join(','),
		// 			signStatus: distance > this.$config.maxDistance ? 2 : 1,
		// 			signAddress: address.result.address,
		// 			signLongitude: res.longitude,
		// 			signLatitude: res.latitude,
		// 		}).then(() => {
		// 			uni.showToast({
		// 				title: '签到成功',
		// 				icon: 'none',
		// 			});
		// 			this.imgaddress = '';
		// 			this.signImg = [];

		// 			this.$refs.popupSign.close();
		// 			this.getDetail();
		// 		});
		// 	}
		// },

		// 签退前确定电梯状态
		showStatusChangeBeforeLeave(res, type) {
			console.log(res, '看看res是什么', '事务');
			let isFinsh = res ? true : false;
			this.handFinish = isFinsh;
			this.signType = 'out';
			const data = {
				signType: this.signType == 'in' ? 1 : 2,
				useLastImg: this.useLastImg,
				orderType: 6,
			};
			this.buttonType = type;
			if (type === 1) {
				// 区分按钮类型发送群消息
				data.buttonType = 1;
				this.buttonType = 1;
			}
			uni.setStorage({
				key: 'signObj',
				data,
			});
			if (this.config.checkSignOut == 1) {
				if (
					this.workOrderDetail.lastSignImg &&
          this.workOrderDetail.lastSignImg.signOutImage
				) {
					// 这里弹出弹框提示是否使用上次的照片
					this.visibleShowTwo = true;
				} else {
					uni.navigateTo({
						url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}&isFinsh=${isFinsh}`,
					});
				}
			} else {
				uni.navigateTo({
					url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}&isFinsh=${isFinsh}`,
				});
			}
		},
		// 签退 post==> 是否签退后立即执行提交操作
		async finishOut() {
			console.log(post, '签退');
			const post = this.handFinish ? true : false;
			this.showLeave = false;
			let localInfo = await this.getLocalInfo();
			if (!localInfo.latitude) {
				uni.showModal({
					title: '提示',
					content: '请打开定位，再签退',
					showCancel: false,
				});
				return;
			}
			// 计算是否范围内打卡
			let distance = getDistance(
				localInfo.latitude,
				localInfo.longitude,
				this.elevatorDetail.latitude,
				this.elevatorDetail.longitude
			);
			if (distance > this.$config.maxDistance) {
				uni.showModal({
					title: '提示',
					content: '当前不在项目位置,是否确定按照当前位置继续签退？',
					success: (res) => {
						if (res.confirm) {
							this.signType = 'out';
							this.signinData = { post: post || false };
							this.imgaddress = '';
							this.signImg = [];
							this.$refs.popupSign.open('center');
						}
					},
				});

				return;
			}
			this.signType = 'out';
			this.imgaddress = '';
			this.signImg = [];
			this.signinData = {
				post: post || false,
			};
			this.$refs.popupSign.open('center');
			return;
		},

		// 签到按钮
		async signintime(e) {
			if (e != 1) {
				console.log('关闭');
				uni.hideLoading();
				this.imgaddress = '';
				this.signImg = [];
				this.$refs.popupSign.close('center');
				return;
			}
			let that = this;

			if (this.imgaddress) {
				await this.getPlanDetail();
				if (this.signType == 'in') {
					if (this.status > 3 || this.isPlanStatus) {
						uni.hideLoading();
						uni.showModal({
							title: '提示',
							content: '签到失败，工单状态已改变',
							showCancel: false,
						});
						return;
					}
				}

				let localInfo = await this.getLocalInfo();
				console.log('localInfo', localInfo);
				let address = await getlocalinfo(
					localInfo.latitude,
					localInfo.longitude
				);
				let signStatus = 1;
				// 计算是否范围内打卡
				let distance = getDistance(
					localInfo.latitude,
					localInfo.longitude,
					this.elevatorDetail.latitude,
					this.elevatorDetail.longitude
				);
				if (distance > this.$config.maxDistance) {
					signStatus = 2;
				}
				// uni.hideLoading()
				// return

				(this.signType == 'in' ? signIn : signOut)(
					this.signType == 'in'
						? {
							userId: that.userinfo.user_id,
							planId: that.planId,
							signImage: that.imgaddress,
							signStatus: signStatus,
							signLongitude: localInfo.longitude,
							signLatitude: localInfo.latitude,
							signAddress: address.result.address,
						}
						: {
							userId: that.userinfo.user_id,
							planId: that.planId,
							signOutImage: that.imgaddress,
							signOutStatus: signStatus,
							signOutLongitude: localInfo.longitude,
							signOutLatitude: localInfo.latitude,
							signOutAddress: address.result.address,
						}
				).then(() => {
					uni.hideLoading();
					uni.showToast({
						title: '提交成功',
						icon: 'none',
						mask: true,
					});

					setTimeout(async () => {
						that.imgaddress = '';
						that.imgUrl = [];
						if (that.signinData.post && that.signType == 'out') {
							console.log('立即执行提交');
							// 立即执行提交
							that.$refs.popupSign.close();
							await that.initData();
							that.handleFinsh(true);
						} else {
							that.$refs.popupSign.close();
							that.initData();
						}

						if (this.signType == 'in') {
							this.visibleShowTwo = true;
						}
					}, 700);
				});
			} else {
				uni.hideLoading();
				uni.showToast({
					title: '请拍照',
					icon: 'none',
				});
			}
		},

		// 验证是否有权限

		getPlanRole() {
			// console.log(this.planDetail);
			let next = false;
			if (!this.planDetail.users) {
				return next;
			}
			for (let i = 0; i < this.planDetail.users.length; i++) {
				if (this.planDetail.users[i].userId == this.userinfo.user_id) {
					next = true;
					break;
				}
			}
			if (!next) {
				uni.showModal({
					title: '提示',
					content: '你没有权限操作该任务',
					showCancel: false,
				});
			}
			return next;
		},

		// 点击提交完成
		async finish() {
			if (this.getPlanRole() == false) {
				return;
			}

			uni.showLoading({
				title: '加载中',
				mask: true,
			});
			// 获取user的接口
			await this.getPlanDetail();
			let cantUsers = [];
			if (this.planDetail.users) {
				for (let i = 0; i < this.planDetail.users.length; i++) {
					if (this.planDetail.users[i].userId == this.userinfo.user_id) {
						if (
							this.planDetail.users[i].signUser &&
              this.planDetail.users[i].signUser.isPlanStatus
						) {
							uni.hideLoading();
							this.finishOut(1);

							return;
						}
					} else {
						if (
							this.planDetail.users[i].signUser &&
              this.planDetail.users[i].signUser.isPlanStatus
						) {
							cantUsers.push(this.planDetail.users[i].userName);
						}
					}
				}
			}

			uni.hideLoading();
			if (cantUsers.length > 0) {
				uni.showModal({
					title: '提示',
					content: `同伴${cantUsers.join(
						'、'
					)}未签退，确定则强制完成，同伴自动签退；取消则等同伴签退`,
					success: (res) => {
						if (res.confirm) {
							this.postPlan();
						}
					},
				});
				return;
			}
			this.postPlan();
		},
		// 提交任务
		async postPlan() {
			uni.hideLoading();
			let localInfo = await this.getLocalInfo();
			if (!localInfo.latitude) {
				uni.showModal({
					title: '提示',
					content: '请打开定位，再提交',
					showCancel: false,
				});
				return;
			}
			uni.showModal({
				title: '提示',
				content: '提交任务后将不可修改，是否提交?',
				success: async (res) => {
					if (res.confirm) {
						uni.showLoading({
							title: '提交中',
							mask: true,
						});

						// let address = await getlocalinfo(
						// 	localInfo.latitude,
						// 	localInfo.longitude
						// );
						// let signStatus = 1;
						// 计算是否范围内打卡

						checkFinish({
							id: this.workOrderDetail.id,
							checkStatus: this.checkStatus,
						})
							.then(() => {
								uni.hideLoading();
								uni.showToast({
									title: '提交成功',
								});
								setTimeout(() => {
									this.getPlanDetail();
									this.initElevtorDetail();
									this.initData();
								}, 500);
							})
							.catch((res) => {
								uni.hideLoading();
								uni.showToast({
									title: res.msg,
									icon: 'none',
								});
								setTimeout(() => {
									this.initData();
								}, 1000);
							});
					}
				},
			});
		},

		// 图片上传
		changeImg(list) {
			console.log('上传图片', list);
			if (list.length > 0) {
				this.imgaddress = list[0];
				this.signImg = list;
			} else {
				this.signImg = list;
			}
		},
		async handleStart() {
			// 先查下工单状态
			await this.getPlanDetail();
			if (this.getPlanRole() == false) {
				return;
			}
			if (!this.showBtns) {
				uni.showModal({
					title: '提示',
					content: '你没有权限操作该任务',
					showCancel: false,
				});
				return;
			}
			let date = new Date(this.planDetail.planDate.replace(/-/g, '/'));
			let now = new Date();
			now.setHours(0, 0, 0);
			console.log(now.getTime() + 1000 * 60 * 60 * 24 + 2000, date.getTime());
			if (date.getTime() > now.getTime() + 1000 * 60 * 60 * 24 - 2000) {
				uni.showModal({
					title: '提示',
					content: '任务未到可执行时间',
					showCancel: false,
				});
				return;
			}
			let isAllow = await this.checkAllowSignFun();
			if (isAllow.isExist) {
				this.checkCanSignOutMsg = isAllow;
				this.signOutModelVisible = true;
				return;
			}

			// 如果设置需要拍照,再判断24小时内是否有签到照片
			// console.log(this.config, "config");
			// return
			this.handFinish = false;
			this.signType = 'in';
			// return;
			const data = {
				signType: this.signType == 'in' ? 1 : 2,
				useLastImg: this.useLastImg,
				orderType: 6,
			};
			uni.setStorage({
				key: 'signObj',
				data,
			});
			if (this.config.checkSigin == 1) {
				if (
					this.workOrderDetail.lastSignImg &&
          this.workOrderDetail.lastSignImg.signImage
				) {
					// 这里弹出弹框提示是否使用上次的照片
					this.visibleShowTwo = true;
				} else {
					uni.navigateTo({
						url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}`,
					});
				}
			} else {
				uni.navigateTo({
					url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}`,
				});
			}
		},
		addRecord() {
			// 如果没有签到过不能操作
			console.log(this.userSignCount, this.status);
			if (this.userSignCount == 0 && this.status == 4) {
				return;
			}
			if (!this.isPlanStatus && this.status < 4) {
				uni.showToast({
					title: '请先签到后在进行添加',
					icon: 'none',
					mask: true,
				});
				return;
			} else {
				// this.$refs.popup.open();
				this.recordPopupShow = true;
				this.overflowShow = true;
				this.$nextTick(() => {
					this.$refs['add-nopass-record'].initRecord({
						isEdit: false,
					});
				});
			}
		},
		closeRecord() {
			this.$refs.popup.close();
			this.aa = '0';
		},
		// 关闭提交按钮
		async handleSubmit() {
			console.log('提交按钮');
			this.recordPopupShow = false;
			this.overflowShow = false;
			await this.getDetail();
			let that = this;
			const query = uni.createSelectorQuery().in(that);
			query
				.select('.quality-record')
				.boundingClientRect((data) => {
					console.log(data, 666);
					uni.pageScrollTo({
						scrollTop: data.height,
						duration: 0,
					});
				})
				.exec();
		},
		// 拨打电话
		handleCall() {
			this.$nextTick(() => {
				this.$refs.property.$refs.propertyPhone.open();
			});
		},
		closePhone() {
			this.$nextTick(() => {
				this.$refs.property.$refs.propertyPhone.close();
			});
		},
		// 查看是否有正在编辑的记录
		editingRecord({ isEdit }) {
			this.isEditFlag = isEdit;
		},
		// 删除记录
		async updateRecord() {
			await this.getDetail();
		},

		// 确认完成按钮点击
		async finishComfire() {
			// 先查询下任务状态
			await this.getPlanDetail();
			// 先判断同伴签退没
			this.visibleShow = false;
			// 如果自己没有签退先去签退页面
			if (this.isPlanStatus) {
				setTimeout(() => {
					this.handFinish = true;
					this.showStatusChangeBeforeLeave(true, 1);
				}, 1000);
				return;
			}

			let cantUsers = [];

			if (this.planDetail.users) {
				for (let i = 0; i < this.planDetail.users.length; i++) {
					if (this.planDetail.users[i].userId == this.userinfo.user_id) {
						if (
							this.planDetail.users[i].signUser &&
              this.planDetail.users[i].signUser.isPlanStatus
						) {
							uni.hideLoading();
							this.handFinish = true;

							this.showStatusChangeBeforeLeave(true);

							return;
						}
					} else {
						if (
							this.planDetail.users[i].signUser &&
              this.planDetail.users[i].signUser.isPlanStatus
						) {
							cantUsers.push(this.planDetail.users[i].userName);
						}
					}
				}
			}
			// uni.hideLoading();
			this.cantUsersArr = cantUsers;
			console.log(this.cantUsersArr, '签退的人员');
			if (cantUsers.length > 0) {
				uni.showModal({
					title: '提示',
					content: `同伴${cantUsers.join(
						'、'
					)}未签退，确定择强制完成，同伴自动签退；取消则等同伴签退`,
					success: async (res) => {
						if (res.confirm) {
							this.checkFinishPost();
						}
					},
				});
			} else {
				// 请求完成
				console.log('请求完成');
				this.checkFinishPost();
			}
		},
		// 点击完成任务
		async handleFinsh() {
			// 如果已完成return
			if (this.status === 4) {
				return;
			}
			// 初始化签退-完成逻辑
			this.handFinish = false; 
			// 如果没有添加记录提示
			if (
				this.maintainMalfunctionHistories.length === 0 &&
        this.checkStatus == 2
			) {
				uni.showToast({
					title: '请先添加任务记录再点击完成任务',
					icon: 'none',
					mask: true,
				});
				// 这里定位到空的数据框
				this.emptyRecord = true;
				let that = this;
				const query = uni.createSelectorQuery().in(that);
				query
					.select('.empty')
					.boundingClientRect((data) => {
						console.log(data.top, 666);
						uni.pageScrollTo({
							scrollTop: data.top,
							duration: 0,
						});
					})
					.exec();

				return;
			}
			// 如果是立即完成
			// this.handFinish=res
			// 判断一下同伴是否未签退
			this.visibleShow = true;
		},
		// 质检完成请求接口
		checkFinishPost() {
			uni.showLoading({
				title: '提交中',
				mask: true,
			});
			/* 定位上报埋点*/
			this.reportAddress({
				userId: this.userinfo.user_id,
				operation: 5,
				planId: this.planId,
				recordType: 1, 
			});
			/* 定位上报埋点 end*/
			checkFinish({
				id: this.workOrderDetail.id,
				checkStatus: this.checkStatus,
			}).then(async (res) => {
				if (res.data) {
					await this.initData();
					uni.hideLoading();
				}
			});
		},

		// 多人维修检查状态
		handleDone() {
			// console.log("工单完成");
			uni.showToast({
				title: '工单状态已更新,请重新进入页面',
				icon: 'none',
			});
			setTimeout(() => {
				uni.navigateBack({});
			}, 500);
		},
		getAliasStr(str) {
			if (!str) {
				return '';
			}
			if (str.length > 20) {
				return '(项目别名：' + str.slice(0, 20) + '...)';
			} else {
				return '(项目别名：' + str + ')';
			}
		},
		// 导航
		handleGuide() {
			console.log(this.elevatorDetail, 6666);
			const {
				buildingName,
				relationAlias,
				latitude,
				longitude,
				buildingAddress,
			} = this.elevatorDetail;
			let alias = relationAlias;
			let aliasName = alias.length
				? alias
					.map((item) => {
						return item.alias;
					})
					.join(',')
				: '';
			uni.getLocation({
				// 返回可以用于uni.openLocation的经纬度
				type: 'gcj02', 
				success: () => {
					console.log(latitude, longitude);
					uni.openLocation({
						latitude: Number(latitude),
						longitude: Number(longitude),
						scale: 18,
						name: buildingName + this.getAliasStr(aliasName),
						address: buildingAddress,
						success: () => {
							console.log('success');
						},
					});
				},
			});
		},
		getConfig() {
			return new Promise((resolve) => {
				getConfig().then((res) => {
					if (res) {
						this.config = res.data.config;
						// console.log(this.config, "this.config");
					}
				});
				resolve();
			});
		},
		checkAllowSignFun() {
			return new Promise((resolve) => {
				checkCanSignOut({ planId: this.planId }).then((res) => {
					if (res) {
						resolve(res.data);
					}
				});
			});
		},
	},
};
</script>
<style>
page {
  height: 100%;
  background-color: #f3f6f8;
  font-size: 28rpx;
}
</style>

<style lang="scss" scoped>
$all_width: 96rpx;
$all_height: 96rpx;

.movable-area {
  height: 100vh;
  width: 750rpx;
  top: 0;
  position: fixed;
  z-index: 300;
  pointer-events: none; //此处要加，鼠标事件可以渗透

  .movable-view {
    width: $all_width;
    height: $all_height;
    pointer-events: auto; //恢复鼠标事件

    image {
      width: $all_width;
      height: $all_height;
    }
  }
}

.lastImg {
  padding: 30rpx 0 60rpx 0;
  text-indent: 2em;
}

.finishDateContent {
  display: flex;
  justify-content: space-between;
  padding-bottom: 24rpx;
  color: #666;
  border-bottom: 2rpx solid #e9e9e9;
  margin-bottom: 22rpx;

  .timeArea {
    display: flex;
    align-items: center;

    image {
      width: 32rpx;
      height: 32rpx;
    }
  }
}

.emptyBox {
  margin-left: 20rpx;
  margin-bottom: 38rpx;
}

.empty {
  flex-direction: column;
  border-radius: 8rpx;
  height: 172rpx;
  border: 2rpx solid #e9e9e9;
  padding-bottom: 30rpx;
}

.errorEmpty {
  border-color: #e02020;
}

.addressBox {
  width: 710rpx;
  margin: 0 auto;
  background: #fff;
  border-radius: 8rpx;
  font-size: 24rpx;
  padding: 20rpx 22rpx 16rpx 16rpx;
  font-size: 24rpx;
  color: #999;
  box-sizing: border-box;
  margin-bottom: 20rpx;
  // position: relative;
  // z-index: 110;
  display: flex;

  .top {
    display: flex;

    .name {
      display: flex;
      // padding-left: 14rpx;
      font-weight: 600;
      color: #333;
      align-items: center;
      view{
        margin-left: 10rpx;
      }
    }

    image {
      width: 32rpx;
      height: 32rpx;
    }
  }

  .buildAddressBox {
    display: flex;
  }

  .buildAddress {
    padding: 6rpx 20rpx 0 32rpx;
    margin-left: 10rpx;
    width: 388rpx;
    margin-right: 30rpx;
    display: flex; 
    align-items: center;

    .buildings {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 388rpx;
      font-size: 20rpx;
      color: #666;
    }
  }

  .addressBox_right {
    display: flex;
    flex: 1;
    justify-content: flex-end;

    align-items: center;
  }

  .gpsAndCall {
    position: relative;
    display: flex;
    align-items: center;
    width: 190rpx;
    color: #666;

    .gpsAndCall_item {
      display: flex;
      flex: 1;
    }

    .guide {
      justify-content: flex-end;
    }

    image {
      width: 32rpx;
      height: 32rpx;
    }

    .line {
      width: 2rpx;
      height: 24rpx;
      background: #e9e9e9;
      position: absolute;
      left: 50%;
      top: 6rpx;
    }
  }
}

.statusArea {
  padding: 10rpx 20rpx;
  background: #ffffff;
  border-radius: 8rpx;
  display: flex;
  font-size: 26rpx;
  position: absolute;
  font-weight: 500;
  right: 20rpx;
  top: 40rpx;
  z-index: 120;

  image {
    width: 32rpx;
    height: 32rpx;
  }
}

.qualityDetail {
  .signCircle {
    height: 80rpx;
    width: 80rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #0091ff;
    color: #fff;
    position: fixed;
    z-index: 200;
    border-radius: 50%;
  }

  .nav {
    position: sticky;
    top: 0;
    z-index: 112;
  }

  .bg {
    width: 750rpx;
    height: 354rpx;
    position: absolute;
    top: 0;
  }

  .header {
    padding-left: 40rpx;
    padding-right: 32rpx;
    margin-bottom: 50rpx;
    padding-top: 28rpx;
    position: relative;
  }

  .progressBar_elevator {
    width: 710rpx;
    margin: 0 auto;
    background: #fff;
    border-radius: 8rpx;
    margin-bottom: 20rpx;
    display: flex;
    height: 84rpx;
    line-height: 84rpx;
    z-index: 300;

    view:nth-of-type(1) {
      flex: 1;
      font-size: 32rpx;
      font-weight: 500;
      color: #333333;
      margin-left: 20rpx;
    }

    view:nth-of-type(2) {
      flex: 0 0 200rpx;
      text-align: right;
      font-size: 26rpx;
      color: #0091ff;
      border-radius: 8rpx;
      padding: 0rpx 30rpx;
      vertical-align: middle;

      text {
        margin-right: 8rpx;
      }

      image {
        width: 32rpx;
        height: 32rpx;
        vertical-align: middle;
      }
    }
  }

  .content_box {
    padding: 0 20rpx;
    background-color: #f3f6f8;
    padding-bottom: 150rpx;
    position: relative;

    .content_item {
      margin-bottom: 20rpx;
      padding: 28rpx 20rpx;
      border-radius: 8rpx;
      background: #ffffff;

      .notic {
        padding-left: 20rpx;
      }

      .title {
        font-size: 32rpx;
        color: #333;
        font-weight: 600;
        padding-bottom: 22rpx;
      }

      .result {
        display: flex;
        padding-left: 10rpx;
        justify-content: space-between;

        .result_item {
          border-radius: 8rpx;
          height: 70rpx;
          width: 300rpx;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #fff;
          background: #ccc;
        }
      }

      .des {
        display: flex;
        margin-bottom: 16rpx;

        .label {
          width: 130rpx;
          margin-right: 16rpx;
          color: #999;
        }

        :nth-child(2) {
          display: flex;
          flex: 1;
          flex-wrap: wrap;
        }
      }

      .notic {
        // width: 100%;
        padding-bottom: 20rpx;
        padding-left: 20rpx;

        text {
          color: #e54b4b;
        }

        .name {
          display: flex;
          font-size: 26rpx;
          color: #333;
          margin-bottom: 16rpx;
        }

        .area {
          padding: 20rpx;
          border: 2rpx solid #e9e9e9;
          margin-bottom: 20rpx;
        }
      }

      textarea {
        font-size: 28rpx;
      }

      .length {
        text-align: right;
        // padding-bottom: 20rpx;
        color: #ccc;
      }

      .info-item {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        color: #333;
        align-items: baseline;

        &-label {
          width: 130rpx;
          color: #999;
          margin-right: 16rpx;
        }

        &-content {
          flex: 1;
          line-height: 35rpx;
        }

        &-word {
          color: #0091ff;
          flex: 1;
          flex-direction: column;

          .fileName {
            width: 520rpx;
            // background: pink;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
      }

      .imgs {
        width: 100%;
        display: flex;
        flex-wrap: wrap;

        image {
          width: 113rpx;
          height: 113rpx;
          margin-right: 20rpx;
          margin-top: 20rpx;
        }
      }

      .faultImg {
        display: flex;
        flex-wrap: wrap;

        image {
          width: 120rpx;
          height: 120rpx;
          margin-right: 18rpx;
        }
      }

      .label {
        margin-right: 16rpx;
        color: #999999;
        font-size: 28rpx;
        width: 130rpx;
        // background: pink;
      }

      .falutItem {
        display: flex;
        align-items: center;
        margin-bottom: 16rpx;

        .tag {
          border: 2rpx solid #0091ff;
          border-radius: 8rpx;
          padding: 4rpx 24rpx;
          font-size: 26rpx;
          color: #0091ff;
        }
      }

      .orderfalutDes {
        :nth-child(1) {
          width: 200rpx;
        }

        margin-bottom: 40rpx;
      }
    }
    .problemBox{
      padding-left: 0;
      .title{
        padding-left: 20rpx;
      }
    }
    .userListBox{
      padding: 20rpx 0
    }
    .progressBar {
      display: flex;
      justify-content: center;
      margin-bottom: 20rpx;

      .progressBar_content {
        width: 710rpx;
        // height: 284rpx;
        background: #ffffff;
        border-radius: 8rpx;
        padding: 24rpx 22rpx 0rpx 18rpx;
        box-sizing: border-box;
       
      }
    }
  }
.completeBox{
  text-align: center;
  view:nth-child(2){
    color: #e02020;
     padding-top: 10rpx; 
     font-size: 24rpx
  }
}
  .bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 12;
    background-color: #fff;
    height: 100rpx;
    width: 100%;
    display: flex;
    border-top: 2rpx solid #eeeeee;
    box-sizing: border-box;
    padding: 0 20rpx;

    view {
      // height: 100%;
      display: flex;
      align-items: center;
    }

    .left {
      width: 200rpx;
      font-size: 20rpx;

      .left_item {
        display: flex;
        flex-direction: column;
        flex: 1;

        view {
          width: 100%;
          display: flex;
          flex: 1;
          justify-content: center;
          // background: red;
          color: #666;
        }

        image {
          width: 48rpx;
          height: 48rpx;
        }
      }
    }

    .right {
      flex: 1;

      .start {
        // width: 524rpx;
        height: 70rpx;
        background: #0091ff;
        border-radius: 8rpx;
        color: #fff;
        display: flex;
        flex: 1;

        .finBtn {
          width: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
          background: #ccc;
          flex: 1;
          height: 100%;
          border-radius: 0rpx 8rpx 8rpx 0rpx;
        }

        .editApplyBtn {
          display: flex;
          flex: 1;
          align-items: center;
          justify-content: center;
          background: #f5fbff;
          height: 100%;
          color: #0091ff;

          .size {
            width: 30rpx;
            height: 30rpx;
            border-radius: 50%;
            background: red;
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }
      }

      .repariing {
        // width: 100%;
        display: flex;
        flex: 1;
        justify-content: space-between;
        align-items: center;

        view {
          display: flex;
          flex: 1;
          justify-content: center;
          height: 70rpx;
          font-size: 26rpx;
        }

        .blue {
          border-radius: 8rpx 0 0 8rpx;
          color: #0091ff;
          background: #f5fbff;
        }

        .add {
          background: #0091ff;
          color: #fff;
          border-radius: 0 8rpx 8rpx 0;
        }

        .addRed {
          position: relative;

          text {
            position: absolute;
            top: -10rpx;
            right: 0;
            width: 30rpx;
            height: 30rpx;
            background: red;
            border-radius: 15rpx;
            font-size: 20rpx;
            text-align: center;
          }
        }

        .finish {
          background: #efefef;
          color: #cccccc;
          font-size: 26rpx;
        }
      }
    }
  }

  .change_elevator {
    display: flex;
    flex-direction: row;
    justify-content: center;

    .actElevator {
      // background-color: #0091ff;
      font-size: 24rpx !important;
      color: #0091ff !important;
      border: 2rpx #0091ff solid !important;
    }

    view:nth-of-type(1) {
      // background-color: #0091ff;
      color: #666;
      height: 72rpx;
      width: 176rpx;
      line-height: 72rpx;
      text-align: center;
      border-radius: 8rpx;
      border: 2rpx #ccc solid;
      font-size: 24rpx;
      margin-right: 60rpx;
    }

    view:nth-of-type(2) {
      font-size: 24rpx;
      color: #666;
      height: 72rpx;
      width: 176rpx;
      line-height: 72rpx;
      text-align: center;
      border-radius: 8rpx;
      border: 2rpx #ccc solid;
    }
  }
}
</style>
